package logic

import (
	"context"
	"fmt"
	"go-zero-example/shorturl/api/internal/types"
	"go-zero-example/shorturl/rpc/transform/transformer"

	"github.com/tal-tech/go-zero/core/logx"
	"go-zero-example/shorturl/api/internal/svc"
)

type ExpandLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewExpandLogic(ctx context.Context, svcCtx *svc.ServiceContext) ExpandLogic {
	return ExpandLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

/*func (l *ExpandLogic) Expand(req types.ExpandReq) (*types.ExpandResp, error) {
	// todo: add your logic here and delete this line

	return &types.ExpandResp{}, nil
}*/

func (l *ExpandLogic) Expand(req types.ExpandReq) (types.ExpandResp, error) {

	logx.Info("日志输出测试")

	fmt.Printf("请求ExpandReq数据 %s...\n", req)
	fmt.Printf("请求数据ExpandReq类型 %T...\n", req.Shorten)
	fmt.Printf("请求数据类型ExpandReq内容 %s...\n", req.Shorten)
	fmt.Printf("请求数据类型ExpandReq内容 %s...\n", req.Shorten)


	// 手动代码开始
	resp, err := l.svcCtx.Transformer.Expand(l.ctx, &transformer.ExpandReq{
		Shorten: req.Shorten,
	})

	fmt.Printf("请求数据类型ExpandReq的resp类型 %T...\n", resp)
	fmt.Printf("请求数据类型ExpandReq的err内容 %s...\n", err)


	if err != nil {
		return types.ExpandResp{}, err
	}

	return types.ExpandResp{
		Url: resp.Url,
	}, nil
	// 手动代码结束
}


